package edu.colorado.cs.correll.cudroplet.shaperecognition;

import processing.core.PApplet;

public class SimpleRobot extends Robot {
	public SimpleRobot(ShapeRecognition shapeRecognition, int id, float x,
			float y, float theta) {
		super(shapeRecognition, id, x, y, theta);
	}

	public void update() {
		if (state == RobotState.SEARCH) {
			// random walk until we find a spot on a boundary that isn't
			// in an exclusion radius
			int step_rate = shapeRecognition.simulation.swarm.robotSettings.step_rate;
			float theta_rate = shapeRecognition.simulation.swarm.robotSettings.theta_rate;
			float dx = shapeRecognition.random(-step_rate, step_rate);
			float dy = shapeRecognition.random(-step_rate, step_rate);
			float dtheta = shapeRecognition.random(-theta_rate, theta_rate);
			x += dx;
			y += dy;
			theta += dtheta;
			x = PApplet.constrain(x, 0, shapeRecognition.width - 1);
			y = PApplet.constrain(y, 0, shapeRecognition.height - 1);
			int pix = getPix();
			// detect only red boundaries
			if (pix == shapeRecognition.color(255, 0, 0)) {
				x -= 2 * dx;
				y -= 2 * dy;
			}
			detectBoundary(pix);
		}
	}
}
